using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ShowBallPanel : PanelSingleton<ShowBallPanel>
{
    public Button cyBtn;
    public Button cancelBtn;
    public TMP_InputField inputField;
    Text displayTxt;
    private void Start()
    {
        cyBtn = FindNode(gameObject, "Copy").GetComponent<Button>();
        cancelBtn = FindNode(gameObject, "Cancel").GetComponent<Button>();
        inputField = FindNode(gameObject, "InputField").GetComponent<TMP_InputField>();
        cancelBtn.onClick.AddListener(() =>
        {
            Close();
        });
        displayTxt = FindNode(gameObject, "DisplayText").GetComponent<Text>();
        cyBtn.onClick.AddListener(() =>
        {
            
            UnityEngine.GUIUtility.systemCopyBuffer = inputField.text;
        });
    }
    public override void Open()
    {
        base.Open();
        StringBuilder builder = new StringBuilder();
        MainScripts.Instance.resoult.Sort((a,b) => { return (a.X*100 + a.Y *10+ a.Z).CompareTo(b.X*100 + b.Y *10+ b.Z); });
        for (int i = 0; i < MainScripts.Instance.resoult.Count; i++)
        {
            builder.Append(MainScripts.Instance.resoult[i]);
            if (i < MainScripts.Instance.resoult.Count - 1)
            {
                builder.Append(",");
            }
        }
        displayTxt.text = MainScripts.Instance.resoult.Count.ToString();
        inputField.text = builder.ToString();
    }
}
